<?php

/*****************************************
Tiered Discounting for Bulk Purchases
******************************************/
function addTieredDiscount($amounts, $qtys,$dc,$description) {
		
	//Some variables for the output
	$amounts = explode(',',$amounts);
	$qtys = explode(',',$qtys);
	
	//This will hold a count of how many items are in the cart from a certain category.
	$category_qty = $_SESSION["gCartInfo"]['discounts'][$dc]['quantity'];
	$category_price = $_SESSION["gCartInfo"]['discounts'][$dc]['total'];

	//Count the items in this category
	/* No longer necessary.
	foreach($_SESSION["tempCart"] as $item) {
		if($item['discount'] == $dc) {
			$category_qty += $item['quantity'];
			$category_price += $item['price'] * $item['quantity'];
			}
		}
	*/
	//echo "<h1>Discounts</h1><p>Found $category_qty matching items.  They total $category_price.";

	if($category_qty > $qtys[0]) {
		for($i = 0; $i < count($amounts); $i++) {
			if($category_qty > $qtys[$i]){
				$discount = $category_price * $amounts[$i] * -1;
				$discStr = $amounts[$i] * 100;
				$name = "$discStr% Discount";
				$description = "$description";
				$_SESSION["gDiscountRate"] = $amounts[$i];
				}
			}
	
		$_SESSION["gDiscounts"][$dc] = array('name' => $name, 
											  'description' => $description, 
											  'quantity' => '1', 
											  'price' => $discount,
											  'sku' => 'discount',
											  'weight' => '0');
		
		/*echo "  The discount totals $discount.</p>";
		} else if ($_SESSION["gDiscounts"][$dc]) {
			unset($_SESSION["gDiscounts"][$dc]);
			echo "  You have not met any discount criteria yet.</p>";
			} else echo "  You have not met any discount criteria yet.</p>";*/
	} else {
		unset($_SESSION["gDiscounts"][$dc]);
		unset($_SESSION["gDiscountRate"]);
		}
}

/*****************************************
Tiered Discounting for Bulk Purchases
******************************************/
function addAgeFee($fee,$dc,$name,$description) {
		
	
	//If an item in this category exists, they must pay for Age Verification.
	if($_SESSION["gCartInfo"]['discounts'][$dc]['quantity'] > 0) {

		//The criteria was met, add in the fee.
		$_SESSION["gFees"][$dc] = array('name' => $name, 
											  'description' => $description, 
											  'quantity' => '1', 
											  'price' => $fee,
											  'sku' => $dc,
											  'weight' => '0');

	} else unset($_SESSION["gFees"][$dc]);
}

function addItem($price,$sku,$name,$description) {
		$_SESSION["gFees"][$sku] = array('name' => $name, 
											  'description' => $description, 
											  'quantity' => '1', 
											  'price' => $price,
											  'sku' => $sku,
											  'weight' => '0');

	}
?>